<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>封装数据</title>
</head>
<body>
    <script>
    var myObject = (function () {
        var __name = 'sven'; // 私有（private）变量
        return {
            getName: function () { // 公开（public）方法
                return __name;
            }
        }
    })();
    console.log(myObject.getName()); // 输出：sven
    console.log(myObject.__name) // 输出：undefined

    </script>
</body>
</html>